package com.businesscard.system.interceptor;

import com.businesscard.system.entity.Admin;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 管理员拦截器
 */
public class AdminInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Admin admin = (Admin) session.getAttribute("admin");
        
        // 如果管理员未登录，则重定向到管理员登录页面
        if (admin == null) {
            response.sendRedirect("/admin/login");
            return false;
        }
        
        return true;
    }
} 